<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/11/27
 * Time: 14:01
 */
namespace app\mec\controller;
use think\Db;
class Money extends Base {

    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $where2 = [];
            $where2['dlmx_dl_id'] = session('uid1');
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $where2['dlmx_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $where2['dlmx_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $where2['dlmx_time'] = ['between time',[$start,$end]];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('dlmx')
                ->where($where2)
                ->count();// 获取总条数
            $lists = Db::name('dlmx')
                ->where($where2)
                ->page($Nowpage,$limits)
                ->order('dlmx_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $info = Db::table('up_dl')->where('dl_id',session('uid1'))->find();
        $this->assign('info',$info);
        return $this->fetch();
    }
    public function recharge(){
        if(request()->isAjax ()){
            extract(input());
            $where2 = [];
            $where2['less_dl_id'] = session('uid1');
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $where2['less_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $where2['less_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $where2['less_time'] = ['between time',[$start,$end]];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_dl_less')->alias('l')
                ->join('up_shops s', 'l.less_s_id = s.s_id','left')
                ->where($where2)
                ->count();// 获取总条数
            $lists = Db::table('up_dl_less')->alias('l')
                ->join('up_shops s', 'l.less_s_id = s.s_id','left')
                ->where($where2)
                ->page($Nowpage,$limits)
                ->order('less_time desc')
                ->field('l.*,s_name')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $info = Db::table('up_dl')->where('dl_id',session('uid1'))->find();
        $this->assign('info',$info);
        return $this->fetch();
    }
}